package ynu.edu.controller;

import com.netflix.appinfo.InstanceInfo;

import jakarta.annotation.Resource;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import ynu.edu.entity.Cart;
import ynu.edu.entity.User;
import ynu.edu.feign.ServiceProviderService;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Resource
    private ServiceProviderService serviceInstance;

    @GetMapping("/getCartById/0/{userId}")
    public Cart getCartById(@PathVariable("userId") Integer userId){
        Cart cart = new Cart();
        List<String> goods=new ArrayList<>();
        goods.add("玩具");
        goods.add("小汽车");
        cart.setGoodList(goods);
        User u =serviceInstance.getUserById(userId);
        cart.setUser(u);
        return cart;
    }

    @PostMapping("/createUser")
    public User createUser(@RequestBody User user) {
        return serviceInstance.createUser(user);
    }

    @PutMapping("/updateUser")
    public String updateUser(@RequestBody User user) {
        serviceInstance.updateUser(user);
        return "更新成功!";
    }

    @DeleteMapping("/deleteUser/{userId}")
    public String deleteUser(@PathVariable("userId") Integer userId) {
        serviceInstance.deleteUser(userId);
        return "User with ID " + userId + " deleted.";
    }
}
